*** REPLICATION TOOLKIT ***

* AUTHORS: CIMINELLI DUVAL FURCERI 

* ARTICLE: EMPLOYMENT PROTECTION DEREGULATION AND LABOR SHARES IN ADVANCED ECONOMIES 

* JOURNAL: REVIEW OF ECONOMICS AND STATISTICS

* OUTPUT: TABLE G5 (Online Appendix)

***************************

cd ""

putexcel set "Tables/G5", modify 

global horizon 6 

use "DTA files/Dataset", clear

************ PREPARE DATASET **********

* Drop Norway (labor share N/A)
drop if country=="Norway"

* Drop aggregate industries
drop if industry=="C" | industry=="G" | industry=="H" | industry=="J" | industry=="OtU" | industry=="MARKT" | industry=="TOT" | industry=="RtS" 

* Drop industries T and U (labor share N/A)
drop if industry=="T" | industry=="U"

* Set panel
xtset id_cross_section year

************ PREPARE VARIABLES **********

* Labor share
gen Y = 100*lab / va

* Dependent variables
foreach v in Y {
gen `v'1 = `v'-l.`v'
forvalues i = 2 / $horizon {
local sc = `i'-1
gen `v'`i' = f`sc'.`v'-l.`v'
}
}

* Lags dependent variable
foreach v in Y {
forvalues l = 1 / 4 {
gen l`l'`v' = l`l'.`v'1
}
}

* Change reform variables to 0 for public sector industries, agriculture and construction 
replace EPLregularworkers = 0 if industry=="P" | industry=="Q" | industry=="O" | industry=="A" | industry=="F"
replace EPLtemporaryworkers = 0 if industry=="P" | industry=="Q" | industry=="O" | industry=="A" | industry=="F" 

* Epsilon
gen epsilon1 = (EOS_serv4_OLS-1)/EOS_serv4_OLS

* Main explanatory variable (EPL reform regular contract interacted with industry-specific characteristics) 
* normalized so to show differential responses between 25th and 75th percentiles
gen s2 = layoff_rate 
gen s3 = -epsilon1
gen s4 = -epsilon1*layoff_rate
forvalues i = 2 / 4 {
quietly sum s`i' if industry!="P" & industry!="Q" & industry!="O" & industry!="19" & industry!="A" & industry!="F" & industry!="31t33", detail
local sc1 = r(p75)
local sc2 = r(p25)
gen r`i' = (EPLregularworkers*s`i')/(`sc1'-`sc2')  
}

* Lags and forwards of explanatory variables
forvalues s = 2/4 {
forvalues l = 1 / 6 {
gen l`l'r`s' = l`l'.r`s'
}
forvalues f = 1 / 5 {
gen f`f'r`s' = f`f'.r`s'
}
}

* Global for forward variables (Teulings and Zubanov)
forvalues s = 2/4 {
global f1`s'
global f2`s' f1r`s'
global f3`s' f1r`s' f2r`s'
global f4`s' f1r`s' f2r`s' f3r`s'
global f5`s' f1r`s' f2r`s' f3r`s' f4r`s'
global f6`s' f1r`s' f2r`s' f3r`s' f4r`s' f5r`s'
}

* EPL reform temporary contract, interacted with industry-specific characteristics
gen t2 = EPLtemporaryworkers*layoff_rate
gen t3 = -EPLtemporaryworkers*epsilon1
gen t4 = -EPLtemporaryworkers*epsilon1*layoff_rate

************ ANALYSIS **********


forvalues s = 2/4 {
mat mat`s' = J(12,$horizon,.)

forvalues i= 1/$horizon {
* Baseline
reghdfe  Y`i' r`s' l1Y l2Y l3Y l4Y l1r`s' l2r`s' l3r`s' l4r`s' t`s' ${f`i'`s'} if industry!="P" & industry!="Q" & industry!="O" & industry!="19" & industry!="A" & industry!="F" & industry!="31t33", absorb(id_cross_section i.year#id_country i.year#id_industry) cluster(ifscode year) nocons
matrix results = r(table)
mat mat`s'[1,`i'] = results[1,1]
mat mat`s'[2,`i'] = results[2,1]
mat mat`s'[3,`i'] = results[4,1]
* All manufacturing
quietly reghdfe  Y`i' r`s' l1Y l2Y l3Y l4Y l1r`s' l2r`s' l3r`s' l4r`s' t`s' ${f`i'`s'} if industry!="P" & industry!="Q" & industry!="O" & industry!="A" & industry!="F", absorb(id_cross_section i.year#id_country i.year#id_industry) cluster(ifscode year) nocons
matrix results = r(table)
mat mat`s'[4,`i'] = results[1,1]
mat mat`s'[5,`i'] = results[2,1]
mat mat`s'[6,`i'] = results[4,1]
* Control group
quietly reghdfe  Y`i' r`s' l1Y l2Y l3Y l4Y l1r`s' l2r`s' l3r`s' l4r`s' t`s' ${f`i'`s'} if industry!="19" & industry!="31t33" & industry!="A", absorb(id_cross_section i.year#id_country i.year#id_industry) cluster(ifscode year) nocons
matrix results = r(table)
mat mat`s'[7,`i'] = results[1,1]
mat mat`s'[8,`i'] = results[2,1]
mat mat`s'[9,`i'] = results[4,1]
* KLEMS 2017
quietly reghdfe  Y`i' r`s' l1Y l2Y l3Y l4Y l1r`s' l2r`s' l3r`s' l4r`s' t`s' ${f`i'`s'} if industry!="P" & industry!="Q" & industry!="O" & industry!="19" & industry!="A" & industry!="F" & industry!="31t33" &  ifscode != 193 & ifscode != 542 & ifscode != 156 & ifscode != 158, absorb(id_cross_section i.year#id_country i.year#id_industry) cluster(ifscode year) nocons
matrix results = r(table)
mat mat`s'[10,`i'] = results[1,1]
mat mat`s'[11,`i'] = results[2,1]
mat mat`s'[12,`i'] = results[4,1]
}
}

************ SAVE OUTPUT **********

putexcel B4=matrix(mat2)
putexcel B18=matrix(mat3)
putexcel B32=matrix(mat4)
